﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class AddCustomer : System.Web.UI.Page
{
    DBAcess db = new DBAcess();
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Add Employee | Nexus-Z Auto Rental";
        if (Session["employeeID"] == null)
        {
            Response.Redirect("../../Default.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        db.open();
        MySqlCommand cmd = new MySqlCommand("insert into customers values(' " + TextBox1.Text + " ','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + DropDownList1.SelectedValue + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + Session["employeeID"]+ " ')", db.returnCon());
        cmd.ExecuteNonQuery();
        db.close();
        Session["customerID"] = TextBox1.Text;
        Response.Redirect("~/Employee/Customer/EditCustomer.aspx");

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Button1.Enabled = false;
        db.open();
        MySqlCommand cmd = new MySqlCommand("Select * from customers where license_no='"+ TextBox1.Text +"' ;", db.returnCon());
        //cmd.Parameters.AddWithValue("@licenseNumber", TextBox1.Text);
        MySqlDataReader read = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow);
        
        if (read.Read())
        {
            Button1.Enabled = false;
            Label1.Text = "Customer Already Exists";
        }
        else
        {
            Label1.Text = "";
            Button1.Enabled = true;
        }
        db.close();
        
    }
}